﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace NetCoreMvcTest.Utils
{
    public static class ConfigerHelper
    {
        private static object lockObj = new object();

        private static IConfiguration _configuration = null;

        public static IConfiguration Configuration
        {
            get
            {
                Init();
                return _configuration;
            }
        }

        public static string GetAppSettings(string key)
        {
            var section = Configuration?.GetSection("appSettings");
            return section?[key];
        }

        private static void Init()
        {
            if (_configuration == null)
            {
                lock (lockObj)
                {
                    if (_configuration == null)
                    {
                        _configuration = ServiceLocator.Instance.GetService<IConfiguration>();
                    }
                }

            }
        }


    }
}
